/mnt/e/PROGRAMOWANIE/malina/iDom_server_OOP/ftplibpp/ftplib.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*************************************************************************** |
2 | | ftplib.h - description |
3 | | ------------------- |
4 | | begin : Son Jul 27 2003 |
5 | | copyright : (C) 2013 by magnus kulke |
6 | | email : mkulke@gmail.com |
7 | | ***************************************************************************/ |
8 | | |
9 | | /*************************************************************************** |
10 | | * * |
11 | | * This program is free software; you can redistribute it and/or modify * |
12 | | * it under the terms of the GNU Lesser General Public License as * |
13 | | * published by the Free Software Foundation; either version 2.1 of the * |
14 | | * License, or (at your option) any later version. * |
15 | | * * |
16 | | ***************************************************************************/ |
17 | | |
18 | | /*************************************************************************** |
19 | | * Note: ftplib, on which ftplibpp was originally based upon used to be * |
20 | | * licensed as GPL 2.0 software, as of Jan. 26th 2013 its author Thomas * |
21 | | * Pfau allowed the distribution of ftplib via LGPL. Thus the license of * |
22 | | * ftplibpp changed aswell. * |
23 | | ***************************************************************************/ |
24 | | |
25 | | #ifndef FTPLIB_H |
26 | | #define FTPLIB_H |
27 | | |
28 | | #if defined(_WIN32) |
29 | | |
30 | | #if BUILDING_DLL |
31 | | # define DLLIMPORT __declspec (dllexport) |
32 | | #else /* Not BUILDING_DLL */ |
33 | | # define DLLIMPORT __declspec (dllimport) |
34 | | #endif /* Not BUILDING_DLL */ |
35 | | |
36 | | #include <time.h> |
37 | | #endif |
38 | | |
39 | | #ifndef _WIN32 |
40 | | #include <unistd.h> |
41 | | #include <sys/time.h> |
42 | | #endif |
43 | | |
44 | | #ifdef NOLFS |
45 | | #define off64_t long |
46 | | #endif |
47 | | |
48 | | #if defined(__APPLE__) |
49 | | #define off64_t __darwin_off_t |
50 | | #define fseeko64 fseeko |
51 | | #define fopen64 fopen |
52 | | #endif |
53 | | |
54 | | #ifndef NOSSL |
55 | | #include <openssl/ssl.h> |
56 | | #endif |
57 | | |
58 | | #ifndef _FTPLIB_SSL_CLIENT_METHOD_ |
59 | | #define _FTPLIB_SSL_CLIENT_METHOD_ TLSv1_2_client_method |
60 | | #endif//_FTPLIB_SSL_CLIENT_METHOD_ |
61 | | |
62 | | using namespace std; |
63 | | |
64 | | /** |
65 | | *@author mkulke |
66 | | */ |
67 | | |
68 | | typedef int (*FtpCallbackXfer)(off64_t xfered, void *arg); |
69 | | typedef int (*FtpCallbackIdle)(void *arg); |
70 | | typedef void (*FtpCallbackLog)(char *str, void* arg, bool out); |
71 | | |
72 | | #ifndef NOSSL |
73 | | typedef bool (*FtpCallbackCert)(void *arg, X509 *cert); |
74 | | #endif |
75 | | |
76 | | struct ftphandle { |
77 | | char *cput,*cget; |
78 | | int handle; |
79 | | int cavail,cleft; |
80 | | char *buf; |
81 | | int dir; |
82 | | ftphandle *ctrl; |
83 | | int cmode; |
84 | | struct timeval idletime; |
85 | | FtpCallbackXfer xfercb; |
86 | | FtpCallbackIdle idlecb; |
87 | | FtpCallbackLog logcb; |
88 | | void *cbarg; |
89 | | off64_t xfered; |
90 | | off64_t cbbytes; |
91 | | off64_t xfered1; |
92 | | char response[256]; |
93 | | #ifndef NOSSL |
94 | | SSL* ssl; |
95 | | SSL_CTX* ctx; |
96 | | BIO* sbio; |
97 | | int tlsctrl; |
98 | | int tlsdata; |
99 | | FtpCallbackCert certcb; |
100 | | #endif |
101 | | off64_t offset; |
102 | | bool correctpasv; |
103 | | }; |
104 | | |
105 | | #if defined(_WIN32) |
106 | | class DLLIMPORT ftplib { |
107 | | #else |
108 | | class ftplib { |
109 | | #endif |
110 | | public: |
111 | | |
112 | | enum accesstype |
113 | | { |
114 | | dir = 1, |
115 | | dirverbose, |
116 | | fileread, |
117 | | filewrite, |
118 | | filereadappend, |
119 | | filewriteappend |
120 | | }; |
121 | | |
122 | | enum transfermode |
123 | | { |
124 | | ascii = 'A', |
125 | | image = 'I' |
126 | | }; |
127 | | |
128 | | enum connmode |
129 | | { |
130 | | pasv = 1, |
131 | | port |
132 | | }; |
133 | | |
134 | | enum fxpmethod |
135 | | { |
136 | | defaultfxp = 0, |
137 | | alternativefxp |
138 | | }; |
139 | | |
140 | | enum dataencryption |
141 | | { |
142 | | unencrypted = 0, |
143 | | secure |
144 | | }; |
145 | | |
146 | | ftplib(); |
147 | | ~ftplib(); |
148 | | char* LastResponse(); |
149 | | int Connect(const char *host); |
150 | | int Login(const char *user, const char *pass); |
151 | | int Site(const char *cmd); |
152 | | int Raw(const char *cmd); |
153 | | int SysType(char *buf, int max); |
154 | | int Mkdir(const char *path); |
155 | | int Chdir(const char *path); |
156 | | int Cdup(); |
157 | | int Rmdir(const char *path); |
158 | | int Pwd(char *path, int max); |
159 | | int Nlst(const char *outputfile, const char *path); |
160 | | int Dir(const char *outputfile, const char *path); |
161 | | int Size(const char *path, int *size, transfermode mode); |
162 | | int ModDate(const char *path, char *dt, int max); |
163 | | int Get(const char *outputfile, const char *path, transfermode mode, off64_t offset = 0); |
164 | | int Put(const char *inputfile, const char *path, transfermode mode, off64_t offset = 0); |
165 | | int Rename(const char *src, const char *dst); |
166 | | int Delete(const char *path); |
167 | | #ifndef NOSSL |
168 | | int SetDataEncryption(dataencryption enc); |
169 | | int NegotiateEncryption(); |
170 | | void SetCallbackCertFunction(FtpCallbackCert pointer); |
171 | | #endif |
172 | | int Quit(); |
173 | | void SetCallbackIdleFunction(FtpCallbackIdle pointer); |
174 | | void SetCallbackLogFunction(FtpCallbackLog pointer); |
175 | | void SetCallbackXferFunction(FtpCallbackXfer pointer); |
176 | | void SetCallbackArg(void *arg); |
177 | | void SetCallbackBytes(off64_t bytes); |
178 | 0 | void SetCorrectPasv(bool b) { mp_ftphandle->correctpasv = b; }; |
179 | | void SetCallbackIdletime(int time); |
180 | | void SetConnmode(connmode mode); |
181 | | static int Fxp(ftplib* src, ftplib* dst, const char *pathSrc, const char *pathDst, transfermode mode, fxpmethod method); |
182 | | |
183 | | ftphandle* RawOpen(const char *path, accesstype type, transfermode mode); |
184 | | int RawClose(ftphandle* handle); |
185 | | int RawWrite(void* buf, int len, ftphandle* handle); |
186 | | int RawRead(void* buf, int max, ftphandle* handle); |
187 | | |
188 | | private: |
189 | | ftphandle* mp_ftphandle; |
190 | | |
191 | | int FtpXfer(const char *localfile, const char *path, ftphandle *nControl, accesstype type, transfermode mode); |
192 | | int FtpOpenPasv(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); |
193 | | int FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl); |
194 | | int FtpAcceptConnection(ftphandle *nData, ftphandle *nControl); |
195 | | int FtpOpenPort(ftphandle *nControl, ftphandle **nData, transfermode mode, int dir, char *cmd); |
196 | | int FtpRead(void *buf, int max, ftphandle *nData); |
197 | | int FtpWrite(void *buf, int len, ftphandle *nData); |
198 | | int FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData); |
199 | | int FtpClose(ftphandle *nData); |
200 | | |
201 | | int socket_wait(ftphandle *ctl); |
202 | | int readline(char *buf,int max,ftphandle *ctl); |
203 | | int writeline(char *buf, int len, ftphandle *nData); |
204 | | int readresp(char c, ftphandle *nControl); |
205 | | |
206 | | void ClearHandle(); |
207 | | int CorrectPasvResponse(unsigned char *v); |
208 | | }; |
209 | | |
210 | | #endif |